package leetcode.tree;

import leetcode.tree.common.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author mazouri
 * @create 2021-05-04 15:31
 */
public class _129_sumNumbers {
    public int sumNumbers(TreeNode root) {
        if (root == null) return 0;

        return helper(root, 0);
    }

    public int helper(TreeNode root, int num) {
        if (root == null) return 0;
        int sum = num * 10 + root.val;
        if (root.left == null && root.right == null) {
            return sum;
        }

        return helper(root.left, sum) + helper(root.right, sum);
    }
}
